<div class="modal" ng-controller="SaveAppDefinitionCtrl">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header"><h2>{{'APP.POPUP.SAVE-APP-TITLE' | translate}}</h2></div>
      <div class="modal-body">
        <p>{{'APP.POPUP.CREATE-DESCRIPTION' | translate}}</p>
        <div class="alert error" ng-if="saveDialog.errorMessage && saveDialog.errorMessage.length > 0"
             style="font-size: 14px; margin-top:20px">
          <div class="popup-error" style="font-size: 14px">
            <span class="glyphicon glyphicon-remove-circle"></span>
            <span>{{saveDialog.errorMessage}}</span>
          </div>
        </div>
        <div class="form-group">
          <label for="appName">{{'APP.NAME' | translate}}</label>
          <input auto-focus class="form-control" id="appName"
                 ng-disabled="model.loading" ng-model="saveDialog.name" type="text" ui-keypress="{13:'ok()'}">
        </div>
        <div class="form-group">
          <label for="appKey">{{'APP.KEY' | translate}}</label>
          <input class="form-control" id="appKey" ng-disabled="model.loading"
                 ng-model="saveDialog.key" type="text">
        </div>
        <div class="form-group">
          <label for="appDescription">{{'APP.DESCRIPTION' | translate}}</label>
          <textarea class="form-control" id="appDescription" ng-disabled="model.loading"
                    ng-model="saveDialog.description"
                    rows="5"></textarea>
        </div>
        <div class="checkbox" ng-if="currentAppDefinition.definition &&
				    ((currentAppDefinition.definition.models && currentAppDefinition.definition.models.length > 0)
				            || (currentAppDefinition.definition.cmmnModels && currentAppDefinition.definition.cmmnModels.length > 0)) ">

          <label>
            <input ng-model="saveDialog.publish" type="checkbox">
            {{'APP.POPUP.PUBLISH-FIELD' | translate}}
          </label>
        </div>

        <div class="alert error"
             ng-if="error && (error.hasCustomStencilItem || error.hasValidationErrors) && !status.loading"
             style="font-size: 14px; margin-top:20px">
          <div class="popup-error" style="font-size: 14px">
            <span class="glyphicon glyphicon-remove-circle"></span>
            <span ng-if="error.hasCustomStencilItem">{{'APP.POPUP.HAS-CUSTOM-STENCILITEM' | translate:error}}</span>
            <span ng-if="error.hasValidationErrors">{{'APP.POPUP.HAS-VALIDATIONERROR' | translate:error}}</span>
          </div>
        </div>

        <div class="alert-danger app-publish-error"
             ng-if="conflict && conflict.type && conflict.type == 'conflictingProcDefKey'" role="alert">
          <span aria-hidden="true" class="glyphicon glyphicon-exclamation-sign" style="margin-right: 2px"></span>
          <span>{{'APP.POPUP.PUBLISH-ERROR-PROCDEF-KEY-CONFLICT' | translate:conflict.data}}</span>
        </div>

        <div class="alert-danger app-publish-error"
             ng-if="conflict && conflict.type && conflict.type == 'duplicateProcDefKeys'" role="alert">
          <span aria-hidden="true" class="glyphicon glyphicon-exclamation-sign" style="margin-right: 2px"></span>
          <span>{{'APP.POPUP.PUBLISH-ERROR-PROCDEF-DUPLICATE-KEYS' | translate}}</span>
          <ul>
            <li ng-repeat="entry in conflict.data.duplicateProcessDefinitionIds">
              <span ng-repeat="(id, name) in entry">{{id}} ({{name}})</span>
            </li>
          </ul>
        </div>

        <div class="alert-warning app-publish-error"
             ng-if="conflict && conflict.type && conflict.type == 'processModelAlreadyUsed'" role="alert">
          <span aria-hidden="true" class="glyphicon glyphicon-exclamation-sign" style="margin-right: 2px"></span>
          <span>{{'APP.POPUP.PUBLISH-ERROR-PROCESS-ALREADY-USED' | translate}}</span>
          <ul>
            <li ng-repeat="processName in conflict.data.conflictingProcessModelNames track by $index">
              {{processName}} ({{'APP.POPUP.PUBLISH-ERROR-PROCESS-ALREADY-USED-APP' | translate}}
              "{{conflict.data.conflictingAppNames[$index]}}")
            </li>
          </ul>
        </div>

      </div>

      <div class="modal-footer">

        <div class="pull-right"
             ng-if="conflict == null || conflict == undefined || conflict.type != 'processModelAlreadyUsed'">
          <button class="btn btn-sm btn-default" ng-click="cancel()" ng-disabled="model.loading" translate>
            GENERAL.ACTION.CANCEL
          </button>
          <button class="btn btn-primary" ng-click="saveAndClose()"
                  ng-disabled="status.loading || saveDialog.name.length == 0 || saveDialog.key.length == 0"
                  ng-show="!error && !error.hasCustomStencilItem && !error.hasValidationErrors" translate>
            ACTION.SAVE-AND-CLOSE
          </button>
          <button class="btn btn-primary" ng-click="save()"
                  ng-disabled="status.loading || saveDialog.name.length == 0 || saveDialog.key.length == 0"
                  ng-show="!error && !error.hasCustomStencilItem && !error.hasValidationErrors" translate>ACTION.SAVE
          </button>
        </div>

        <div class="pull-right" ng-if="conflict && conflict.type == 'processModelAlreadyUsed'">
          <button class="btn btn-sm btn-default" ng-click="cancel()" ng-disabled="popup.loading" type="button">
            {{'GENERAL.ACTION.CANCEL' | translate}}
          </button>
          <button class="btn btn-sm btn-success" ng-click="saveAndClose(true)" ng-disabled="popup.loading"
                  style="background-color: #5cb85c;border-color: #4cae4c;" type="button">
            <span>{{'GENERAL.ACTION.CONFIRM-AND-CLOSE' | translate}}</span>
          </button>
          <button class="btn btn-sm btn-success" ng-click="save(true)" ng-disabled="popup.loading"
                  style="background-color: #5cb85c;border-color: #4cae4c;" type="button">
            <span>{{'GENERAL.ACTION.CONFIRM' | translate}}</span>
          </button>
        </div>

        <div class="loading pull-right" ng-show="model.loading">
          <div class="l1"></div>
          <div class="l2"></div>
          <div class="l2"></div>
        </div>
      </div>
    </div>
  </div>
</div>
